package com.skcc.ts.nsi.expense;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;

import com.skcc.ts.nsi.MEMain;
import com.skcc.ts.nsi.R;
import com.skcc.ts.nsi.service.SocketClientService;

public class MEExpenseMgmt extends Activity {

	private ImageButton btn_balance_list_search;
	private ImageButton btn_balance_register;
	private ImageButton btn_balance_info;
	private String addr;
	private String port;

	private String myId;

	@Override
	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		setContentView(R.layout.meexpense_mgmt);

		Intent receivedI = getIntent();
		myId = receivedI.getStringExtra("myId");
		addr = receivedI.getStringExtra("loginAddr");
		port = receivedI.getStringExtra("loginPort");

		// default button setting
		initButtons();

		doExpenseMgmt();// ?
	}

	private void doExpenseMgmt() {
		Intent receiveI = getIntent();
		boolean redoYN = receiveI.getBooleanExtra("restart", false);
		if (redoYN) {
			myId = receiveI.getStringExtra("myId");
			addr = receiveI.getStringExtra("loginAddr");
			port = receiveI.getStringExtra("loginPort");
			
			boolean regiSuc = receiveI.getBooleanExtra("regiOk", false);
			if (regiSuc) {
				new AlertDialog.Builder(MEExpenseMgmt.this).setTitle("알림").setMessage("정산내역이 등록되었습니다.").setPositiveButton("OK", null)
						.show();
			} else {

				new AlertDialog.Builder(MEExpenseMgmt.this).setTitle("알림").setMessage("등록된 (미)정산내역이 없습니다").setPositiveButton("OK", null)
						.show();

			}
		}
	}

	/**
	 * <b>메소드 :</b> <b>initButtons</b>
	 * <p>
	 * <ul>
	 * <li>메소드에 대한 설명1
	 * <li>메소드에 대한 설명2
	 * </ul>
	 * </p>
	 * 
	 * @since 2012. 8. 14.
	 */
	private void initButtons() {

		// 정산내역 조회
		btn_balance_list_search = (ImageButton) findViewById(R.id.btn_expense_list_search);
		btn_balance_list_search.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				Intent expSearchI = new Intent(MEExpenseMgmt.this, SocketClientService.class);
				expSearchI.putExtra("id", 41);// 기능분류(비용정산: 정산내역 조회)
				expSearchI.putExtra("myId", myId);
				expSearchI.putExtra("loginAddr",addr);
				expSearchI.putExtra("loginPort", port);
				expSearchI.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
				startService(expSearchI);
				// finish();
			}
		});

		// 정산내역 등록 -> 비용정산으로 변경
		btn_balance_register = (ImageButton) findViewById(R.id.btn_expense_regi);
		btn_balance_register.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				Intent expRegister = new Intent(MEExpenseMgmt.this, SocketClientService.class);
				expRegister.putExtra("id", 43);// 기능분류(비용정산: 정산내역 등록)
				expRegister.putExtra("myId", myId);
				expRegister.putExtra("loginAddr", addr);
				expRegister.putExtra("loginPort", port);
				expRegister.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
				startService(expRegister);
				// finish();
			}
		});

		// 예산 상세정보
		btn_balance_info = (ImageButton) findViewById(R.id.btn_expense_detail);
		btn_balance_info.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				Intent expDetail = new Intent(MEExpenseMgmt.this, SocketClientService.class);
				expDetail.putExtra("id", 44);// 기능분류(비용정산: 예산 상세정보)
				expDetail.putExtra("myId", myId);
				expDetail.putExtra("loginAddr",addr);
				expDetail.putExtra("loginPort",port);
				expDetail.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
				startService(expDetail);
				// finish();
			}
		});
	}
}
